package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.Lecture;
import com.example.haoqisystem.request.CreateLectureRequest;
import com.example.haoqisystem.request.QueryLectureListRequest;
import com.example.haoqisystem.request.UpdateLectureRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.response.PageResult;
import com.example.haoqisystem.service.LectureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "课程api")
@RequestMapping("/lecture")
@RequiredArgsConstructor(onConstructor_ ={@Autowired})
public class LectureController {
    private final LectureService lectureService;

    @ApiOperation(value = "增加课程")
    @PostMapping("/add")
    public BaseResponse<Lecture> add(@RequestBody CreateLectureRequest request){
        return lectureService.add(request);
    }

    @ApiOperation(value = "删除课程")
    @GetMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "课程id",required = true)
    })
    public BaseResponse<String> delete(Long id){
        return lectureService.delete(id);
    }

    @ApiOperation(value = "查看课程详情")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "课程id",required = true),
            @ApiImplicitParam(name = "deleted",value = "是否被逻辑删除",required = true,dataType = "Boolean")
    })
    public BaseResponse<Lecture> detail(Long id,boolean deleted){
        return lectureService.detail(id,deleted);
    }

    @ApiOperation(value = "修改课程内容")
    @PostMapping("/update")
    public BaseResponse<Lecture> update(@RequestBody UpdateLectureRequest request){
        return lectureService.update(request);
    }

    @ApiOperation(value = "分页查询课程列表")
    @PostMapping("/queryPageList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lectureName",value = "课程名（模糊查询）"),
            @ApiImplicitParam(name = "betweenTime",value = "开课时间区间(yyyy-MM-dd 至 yyyy-MM-dd"),
            @ApiImplicitParam(name = "lecturePlace",value = "开课地点（模糊查询）"),
            @ApiImplicitParam(name = "deleted",value = "逻辑删除",required = true,dataType = "Boolean")
    })
    public BaseResponse<PageResult<Lecture>> queryList(QueryLectureListRequest request){
        return lectureService.queryList(request);
    }

    @ApiOperation(value = "课程列表查询")
    @GetMapping("/queryList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lectureName",value = "课程名（模糊查询）"),
            @ApiImplicitParam(name = "betweenTime",value = "开课时间区间(yyyy-MM-dd 至 yyyy-MM-dd)"),
            @ApiImplicitParam(name = "lecturePlace",value = "开课地点（模糊查询）"),
            @ApiImplicitParam(name = "deleted",value = "逻辑删除",required = true,dataType = "Boolean")
    })
    public BaseResponse<List<Lecture>> queryList1(String lectureName,String betweenTime,
                                                  String lecturePlace,Boolean deleted
                                                  ){
        return lectureService.queryList1(lectureName,betweenTime,lecturePlace,deleted);
    }
}
